<template>
	<view>
		<view class="divv news">
			<uni-card class="newsCard" v-for="(item,index) in list" :key="index" @click="goNewDetails(item)">
				<view class="Message">
					<view class="Message-title">
						{{item.newsTitle}}
					</view>
					<view class="Message-desc">
						<view class="reviewNum">
							{{item.reviewNum}}观看
						</view>
						<view class="time">
							{{item.addTime}}
						</view>
					</view>
				</view>
				<view class="newsCard-image">
					<!-- 徐向军本地 -->
					<!-- <image :src="`http://192.168.13.153:8080${item.image}`" mode=""></image> -->
					<!-- https://zhnc.pcippc.com/ -->
					<image :src="`https://zhnc.pcippc.com/api${item.image}`" mode=""></image>
				</view>
			</uni-card>
			<u-loadmore lineColor="#1CD29B" dashed line :status="status" :loading-text="loadingText"
				:loadmore-text="loadmoreText" :nomore-text="nomoreText" />
		</view>
	</view>
</template>

<script>
	import {
		getNewsList
	} from '@/api/news/index.js'
	export default {
		data() {
			return {
				status: 'loadmore',
				loadingText: '加载中',
				loadmoreText: '加载更多',
				nomoreText: '真的没有了',
				// 新闻
				list: [],
				// 参数
				params: {
					pageNum: 1,
					pageSize: 10
				},
				// 总数
				total: 2
			}
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.params.pageNum = 1;
			this.status = 'loading'
			// 请求接口
			this.list=[];
			this.getList()
		},
		// 上拉加载
		onReachBottom() {
			// 当列表数量大于总数量，return
			this.status = 'loading'
			if (this.list.length >= this.total) return this.status = 'nomore';;
			this.params.pageNum++;
			// 请求接口
			this.getList()
		},
		onShow() {
			this.list = []
			this.getList()
		},
		methods: {
			//新闻详情页
			goNewDetails(item) {
				uni.navigateTo({
					url: `/pages/partyBuilding/news/details?details=${encodeURIComponent(JSON.stringify(item))}`
				})
			},
			// 新闻接口
			async getList() {
				const result = await getNewsList(this.params)
				console.log('result', result)
				const data = result.data.result.list
				this.total = result.data.result.total
				this.list = this.list.concat(data)
				// this.list = [{
				// 	image: '/static/partyBuilding/1.jpg',
				// 	title: '在主持十九届中共中央政治局第一次集体学习时发表讲话',
				// 	reviewNum: '1',
				// 	time: '2024-04-11 14:20:00',
				// 	noticeContent: `<view style="color:red">内容是我，我就是内容，我的颜色是红色的view</view>`
				// }]
				uni.stopPullDownRefresh(); //刷新图片关闭
				// 接口
				if (this.list.length >= this.total) {
					this.status = 'nomore';
				} else {
					this.status = 'loadmore';
				}

			},
		}
	}
</script>

<style scoped lang="scss">
	::v-deep.news {
		.newsCard {
			.uni-card__content {
				display: flex;
				justify-content: space-between;

				.newsCard-image {
					image {
						height: 150rpx;
						width: 250rpx;
						border-radius: 10rpx;
					}
				}

				.Message {
					width: 100%;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.Message-title {
						font-weight: 600;
						color: black;
						font-size: $uni-font-size-base ;
						// height: 90rpx;
						overflow: hidden;
						// background-color: red;
						// white-space: ;
						// text-overflow: ellipsis;
					}

					.Message-desc {
						display: flex;
						justify-content: space-between;

						>view {
							padding-right: 20rpx;
						}
					}
				}
			}
		}
	}
</style>